package com.admin.cartAndOrder.service.impl;

import com.admin.cartAndOrder.pojo.MobileEndCart;
import com.admin.cartAndOrder.mapper.MobileEndCartMapper;
import com.admin.cartAndOrder.service.MobileEndCartService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 购物车表 服务实现类
 * </p>
 *
 * @author liu-xiang
 * @since 2022-12-14
 */
@Service
public class MobileEndCartServiceImpl extends ServiceImpl<MobileEndCartMapper, MobileEndCart> implements MobileEndCartService {

    @Autowired
    private MobileEndCartMapper cartMapper;

    public MobileEndCartServiceImpl() {
    }

    public MobileEndCart getCart(Integer id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("orderStatus", Integer.valueOf(0));
        wrapper.eq("id", id);
        return (MobileEndCart) cartMapper.selectOne(wrapper);
    }

    public List getAllCarts(String userNum) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("orderStatus", Integer.valueOf(0));
        wrapper.eq("userNum", userNum);
        return cartMapper.selectList(wrapper);
    }

    public Boolean deleteByIds(Integer[] ids){
        int i=0;
        for(Integer id:ids){
            i+=cartMapper.deleteById(id);
        }
        return i==ids.length;
    }

}
